package br.com.controleFrota;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.database.Cursor;
import android.util.Log;

public class StartBoot extends BroadcastReceiver {

	
	Integer idViagem = null;
	BaseDados dh;
	
    @Override
    public void onReceive(Context context, Intent intent) {
        if ("android.intent.action.BOOT_COMPLETED".equals(intent.getAction())) {
        	
			this.dh = new BaseDados(context);
    		
    		Cursor viagensIniciadas = dh.selectViagemEmAndamento();
    		
    		if (viagensIniciadas.moveToFirst() && viagensIniciadas.getCount() > 0) {
    			
    			Integer idViagem = Integer.parseInt(viagensIniciadas.getString(0));

    			if(idViagem > 0){
    				
            		Intent i = new Intent(context, Painel.class);
    	        	i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    	    		context.startActivity(i);
    	    		
        		}
    		}
        }
    }
    
}